package com.sohoo.nio.data.upload;

import java.net.InetSocketAddress;
import java.net.URLEncoder;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import org.apache.mina.core.service.IoAcceptor;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSessionConfig;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

import com.sohoo.nio.mima.codec.DemoCoderFatory;
import com.sohoo.nio.mima.hander.DemoHandler;

public class DataUpload {
	public static int port = 7001;
	public static void main(String[] args) throws Exception {
		// 加载配置文件
		// 初始化Socket
		final IoAcceptor acceptor = new NioSocketAcceptor();
		IoSessionConfig sessionConfig = acceptor.getSessionConfig();
		sessionConfig.setReadBufferSize(2048);
		sessionConfig.setIdleTime(IdleStatus.BOTH_IDLE, 1);
		// 编写过滤器
		acceptor.getFilterChain().addLast("codec",
				new ProtocolCodecFilter(new DemoCoderFatory()));
		acceptor.setHandler(new DemoHandler());
		acceptor.bind(new InetSocketAddress(port));
		acceptor.bind(new InetSocketAddress(7002));
		acceptor.bind(new InetSocketAddress(7003));
		acceptor.bind(new InetSocketAddress(7004));
		TimerTask timerTask = new TimerTask() {
			@Override
			public void run() {
				acceptor.broadcast(123);
			}
		};
		Timer timer =new Timer();
		timer.scheduleAtFixedRate(timerTask, new Date(), 5000);
	}
	
	
	
}
